package com.jhws.business.comm.service;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.jhws.core.db.BaseDao;
import com.jhws.core.exception.BizException;

/**
 * 小区相关服务
 *
 * @author xiaokek
 * @since 2015年11月29日 上午10:31:43
 */
@Service
public class CommService{

	private BaseDao dao = new BaseDao();

	public List<Map<String, Object>> query(String username) {
		if (!StringUtils.isEmpty(username)) {
			if (username.length() == 12) {
				// 如果是12的房号直接返回小区名
				String commCode = username.substring(0, 4);
				return dao.j().queryForList("select comm_name from tbl_comm_dim where comm_code = ?", commCode);
			}
			List<Map<String, Object>> ownerList = dao.j().queryForList(
					"select room_info_num,comm_name,apply_type from tbl_owner_dim where (apply_type = '0' or apply_type = '2') and owner_mob = ?",
					username);
			if (ownerList != null && ownerList.size() > 0) {
				return ownerList;
			} else {
				throw new BizException("-2", "getCommOfUser", "未注册业主！");
			}
		} else {
			throw new BizException("-1", "getCommOfUser", "帐号不正确！");
		}
	}

	public String queryCommName(String commCode) {
		return dao.j().queryForObject("select comm_name from tbl_comm_dim where comm_code = ?",
				new Object[] { commCode }, String.class);
	}

}
